#!/bin/bash

delete_iptables_rules() {
    # 清空所有表和链的规则
    iptables -t nat -F
    iptables -t filter -F
    iptables -t mangle -F
    iptables -t raw -F
    
    # 重置默认策略为ACCEPT
    iptables -t nat -P PREROUTING ACCEPT
    iptables -t nat -P INPUT ACCEPT
    iptables -t nat -P OUTPUT ACCEPT
    iptables -t nat -P POSTROUTING ACCEPT
    iptables -P INPUT ACCEPT
    iptables -P OUTPUT ACCEPT
    iptables -P FORWARD ACCEPT
    
    # 删除用户自定义链
    iptables -X
    echo -e "\e[32m网络环境恢复\e[0m"
}

stop_redsocks() {
    pkill -f "redsocks.bin" && echo -e "\e[32m已终止redsocks进程\e[0m"
}

main() {
    delete_iptables_rules
    stop_redsocks
}
main
